package com.management.vtribe.controller;

import com.management.vtribe.Bean.User;
import com.management.vtribe.config.Result;
import com.management.vtribe.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/getAllUser")
    public List<User> getAllUser(){
        return userService.getAllUser();
    }

    @RequestMapping("/getUserByUsername")
    public List<User> getUserByUsername(String username){return userService.getUserByUsername(username);}

    @RequestMapping("/getUserById")
    public List<User> getUserById(int id){return userService.getUserById(id);}

    @RequestMapping("/deleteUserById")
    public Result deleteUserById(int id){
        System.out.println("dada:"+id);
        int state = userService.deleteUserById(id);
        if(state==1){return new Result(200,"删除成功！");}
        else{return new Result(400,"删除失败！");}
    }

    @RequestMapping("/updateUserById")
    public Result updateUserById(int id,String state) {
        int res = userService.updateUserById(state,id);
        if(res==1){
            return new Result(200,"修改成功！");
        }else{
            return new Result(400,"修改失败！");
        }
    }
}
